#!/usr/bin/env bash
set -x

# Test that with age.strict=false, mise continues when age key is not available

mise u age

# Generate an age key
age="$(mise x -- age-keygen 2>&1)"
age_pub="$(echo "$age" | grep "# public key:" | awk '{print $4}')"
MISE_AGE_KEY="$(echo "$age" | grep "AGE-SECRET-KEY")"
export MISE_AGE_KEY
# Encrypt the secret and add it to mise.toml
mise set --age-encrypt --age-recipient "$age_pub" SECRET=mysecret

# Verify that mise env works when age key is set
assert_contains "mise env" "SECRET=mysecret"

# Set non-strict mode
mise settings set age.strict false

# Clear age key to simulate missing key
export MISE_AGE_KEY=
rm -f ~/.config/mise/age.txt

# The env should not contain the decrypted secret since key is missing
assert_not_contains "mise env" "export SECRET=mysecret"

# Test with strict=true (default behavior)
mise settings set age.strict true

# This should fail
assert_fail "mise env"
